<template>
	<view class="content">
        <u-navbar bgColor="#fff" :safeAreaInsetTop="true" :placeholder="true" :fixed="true"
            @leftClick="back" :title="title" >
        </u-navbar>
        <view class="u-flex u-row-between u-p-b-20 headerEle" :style="{top:systemInfo.headerH+'px'}">
            <u--input
                class="search-input u-p-l-30 u-p-r-30"
                fontSize="28rpx"
                v-model="paging.keyWord"
                prefixIcon="search"
                prefixIconStyle="font-size:24px"
                :placeholder="placeholder"
                placeholderStyle="fontSize:28rpx"
                clearable
                border="none">
            </u--input>
            <u-button class="search-btn u-m-l-20" type="primary" text="搜索" @tap="searchData"></u-button>
        </view>
        <view style="height:94rpx"></view>


        <view class="uni-area">
            <!-- 班组(未在当前页面进行搜索) -->
            <uni-item-team class="u-m-t-30" v-if="1==2" />
            <!-- 班组成员 -->
            <uni-item-team-member  class="u-m-t-30" v-if="type=='teamMember'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />



            <!-- 人员 -->
            <uni-item-member-plus class="u-m-t-30" v-if="type=='memberPlus'"  
                v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"  >
            </uni-item-member-plus>
            <!-- 工资发放详情 -->
            <uni-item-wage-member class="u-m-t-30" v-if="type=='wagemember'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
            <!-- 预警 -->
            <uni-item-warn class="u-m-t-30" v-if="type=='warn'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />
            <!-- 督办 -->
            <uni-item-supervise class="u-m-t-30" v-if="type=='duban'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />
            <!-- 项目 -->
            <uni-item-project class="u-m-t-30" v-if="type=='project'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />
            <!-- 专户 -->
            <uni-item-fohf class="u-m-t-30" v-if="type=='fohf'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
            <!-- 考勤 -->
            <uni-item-attendance class="u-m-t-30" v-if="type=='attendance'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
            <!-- 工资 -->
            <uni-item-wage v-if="type=='wage'" class="u-m-t-30" />
            <!-- 现场 -->
            <uni-item-scene v-if="type=='scene'" class="u-m-t-30" />



            <!-- 返回顶部 -->
            <u-back-top :scroll-top="page.scrollTop" @tap="toTop"></u-back-top>
            <!-- 加载更多 -->
            <u-loadmore :status="page.status" />
        </view>

        <!-- 提示组件 -->
        <u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                // 设备信息
                systemInfo: uni.getStorageSync('systemInfo'),
                // 用户信息
                userInfo: uni.getStorageSync("userInfo"),
                // 搜索类型
                type: 'search',
                title: '搜索',
                placeholder: '请输入关键字查询信息',
                api: {}, 
                // 分页相关参数
                paging: {
                    pageNum: 1,
                    pageSize: this.$config.pageSize,
                    keyWord: '',
                },
                page: {
                    scrollTop: 0,
                    status: 'nomore',
                    total: 0,
                    list: [], // 列表
                }
			}
		},


        onPageScroll(e) {
            this.page.scrollTop = e.scrollTop
        },
        onReachBottom(){
            if( this.page.list.length < this.page.total ){
                this.paging.pageNum += 1
                this.page.status = 'loading'
                this.getData()
            }else{
                this.page.status = 'nomore'
            }
        },


		onLoad(option) {
            this.type = option.type
            switch (option.type) {
                case 'teamMember':
                    this.title = '班组成员搜索'
                    this.placeholder = '请输入成员姓名/证件号码查询'
                    this.api = this.$apis.GroupMembers
                    this.paging['id'] = option.id // 班组Id
                    break;



                case 'memberPlus': 
                    this.title = '人员管理'
                    this.placeholder = '请输入人员姓名/证件号码查询信息'
                    this.api = this.$apis.MemberList
                    break;
                case 'wagemember': 
                    this.title = '工资发放详情'
                    this.placeholder = '请输入人员姓名/证件号码查询信息'
                    this.paging['ywbh'] = option.ywbh // 发放业务编号
                    this.api = this.$apis.WageMemberList
                    break;
                case 'warn': 
                    this.title = '预警列表'
                    this.placeholder = '请输入项目名称查询信息'
                    this.paging['deptId'] = this.userInfo.deptId // 部门编号【必传】
                    this.paging['gcbh'] = this.userInfo.ssgcbh // 所属工程编号【必传】
                    this.api = this.$apis.WarnList
                    break;
                case 'duban': 
                    this.title = '督办列表'
                    this.placeholder = '请输入项目名称查询信息'
                    this.paging['deptId'] = this.userInfo.deptId // 部门编号【必传】
                    this.paging['gcbh'] = this.userInfo.ssgcbh // 所属工程编号【必传】
                    this.api = this.$apis.DubanList
                    break;
                case 'fohf':
                    this.title = '专户搜索'
                    this.placeholder = '请输入专户名称/专户账号查询'
                    this.api = this.$apis.fohfAccountList
                    break;
                case 'addTeam': 
                    this.title = '新增班组'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'memberleave':
                    this.title = '人员离场'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'membertransfer': 
                    this.title = '人员调岗'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'foreman': 
                    this.title = '班组长变更'
                    this.placeholder = '请输入查询信息'
                    break;

                case 'autonym': 
                    this.title = '实名认证'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'enter': 
                    this.title = '人员进场'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'transfer': 
                    this.title = '人员调岗'
                    this.placeholder = '请输入查询信息'
                    break;
                case 'leave': 
                    this.title = '人员离场'
                    this.placeholder = '请输入查询信息'
                    break;
                
                case 'kaoqin': 
                    this.title = '考勤管理'
                    this.placeholder = '请输入查询信息'
                    break;
            }
		},

        
		methods: {
            // 返回
            back(){
                uni.navigateBack()
            },


            // 搜索
            searchData(){
                this.paging.pageNum = 1
                this.page.list = []
                this.getData()
            },
            // 获取数据
            getData(){
                uni.showLoading({ title:'搜索中' })
                if( this.type == 'warn') this.paging['gcmc'] = this.paging.keyWord
                if( this.type == 'duban') this.paging['gcmc'] = this.paging.keyWord
                // // console.log('搜索参数',this.paging)
                this.$request(this,this.api,this.paging).then(res=>{
                    // // console.log('搜索到的数据',res)
                    if( res.total && res.total != 0 ){
                        this.page.total = res.total
                        this.page.status = 'loadmore'
                        res.data.map((v,i)=>{
                            this.page.list.push(v)
                        })
                    }else{
                        this.page.total = 0
                        this.page.status = 'nomore'
                        this.$tools.uToast(this,'default','','暂未查询到更多相关数据',3000)
                    }
                }).then()
            },
            

            // 回到顶部
            toTop(){
                uni.pageScrollTo({ scrollTop: 0, duration: 300 })
            }
		}
	}
</script>

<style lang="scss">
    .content{
        .headerEle{
            width: 100%;
            position: fixed !important;
            left: 0;
            .search-input{
                width: 534rpx !important;
                box-sizing: border-box;
                height: 74rpx;
                background: #F6F7F8;
            }
            .search-btn{
                width: 136rpx;
                height: 74rpx;
                font-size: 28rpx;
            }
        }
    }
</style>
